<template>
  <div>
    <!-- 顶部滑动条区域 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <!-- 由于接口中没有id  所以在这里滚动条是蓝色，默认选中状态，是因为添加了mui-acitve这个类，如果接口有返回id的话，那么需要绑定类名 判断是否高亮   做法：
          <a  :class="['mui-control-item',item.id==0?'mui-active':'']"  v-for="item in cates" :key="item.createdAt">
            {{item.type}}</a>
          
          可以实现点击谁谁高亮，这个高亮是mui的效果，与tabbar的高亮切换没有关系
          
          -->
          <a
            class="mui-control-item mui-active"
            v-for="item in cates"
            :key="item.createdAt"
          >{{item.type}}</a>
        </div>
      </div>
    </div>
    <!-- 图片列表区域-->
    <ul class="photo-list">
      <!-- tap  与click 一样  但是tap只能在mui组件中用 -->
      <router-link v-for="item in list" :key='item.createdAt' @tap='getPhotoListByCateId()' to="/home/photoinfo"  tag='li'> 
        <img v-lazy="item.profile_image" />
         
         <div class="info">
            <h1 class="info-title">{{item.name}}</h1>
             <div class="info-body">{{item.text}}</div>
         </div>

      </router-link>
    </ul>
  </div>
</template>

<script>
// 导入mui的js文件
import mui from "../../lib/mui/js/mui.min.js";

export default {
  data() {
    return {
      cates: [], //所有分类的列表数组
      list:[]
 };
  },
  created() {
    this.getAllCategory();
    this.getPhotoListByCateId();
  },
  mounted() {
    //当组件中的DOM结构呗渲染好并放到页面中后，会执行这个钩子函数
    // 如果要操作元素，最好是在mounted里面，这时候的DOM元素是最新的
    // 初始话滑动组件
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    getAllCategory() {
      this.$http.get("https://www.apiopen.top/meituApi?page=1").then(result => {
        if (result.body.code === 200) {
          console.log(result.body.data);
          this.cates = result.body.data;
        }
      });
    },
    getPhotoListByCateId(){
      this.$http.get("https://www.apiopen.top/satinApi?type=1&page=1").then(result => {
        if (result.body.code === 200) {
          console.log(result.body.data);
          this.list = result.body.data;
        }
      });
    }
  }
};
</script>
<style scoped>
* {
  touch-action: pan-y;
}
.photo-list{
  list-style: none;
  margin: 0;
  padding:10px;
  padding-bottom: 0;
 
}
.photo-list li{
background-color: #ccc;
text-align: center;
margin-bottom: 10px;
box-shadow: 0 0 9px #999;
 position: relative;
}
.photo-list li img{
  width: 100%;
  vertical-align: middle;
}
.photo-list li img[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
.photo-list .info{
  color: white;
  position: absolute;
  bottom: 0;
  text-align: left;
  width: 100%;
  background: rgba(0, 0,0, 0.4);
  max-height: 84px;
}
.photo-list .info .info-title{
  font-size: 14px;
  
}
.photo-list .info .info-body{
  font-size: 13px;

}
</style>
